<div class="page-content" >
            
    <div class="panel panel-default">
        <div class="panel-heading">
            <{$title}>     <a class="btn btn-primary btn-xs" href="<{:U('index',array('type'=>$type,'pid'=>$pid))}>">返回列表</a>
        </div>
        <div class="panel-body">
       <form action="<{:U('Questions/addquestion')}>" method="post" class="form-horizontal">
			<input type="hidden" name="questionid" value="<{$data.questionid}>" />
			<input type="hidden" name="questionparent" value="<{$pid}>" />
			<input type="hidden" name="type" value="<{$type}>" />	
			
			
				<div class="form-group">
                    <label class="col-sm-2 control-label">选择课程</label>
                    <div class="col-sm-8">
                      <select class="combox" id="isubjectselect" target="isectionselect" refurl="<{:U('Subject/get_ajax_section',array('type'=>'_sel'))}>?subjectid={value}" autocomplete="off">
			        		<option value="0">选择课程</option>
					  			<volist name="subject_list" id="vo">
						  			<option value="<{$vo.subjectid}>"><{$vo.subject}></option>
								</volist>	
					  	</select>
				  		<select class="combox" id="isectionselect" target="iknowsselect" refurl="<{:U('Subject/get_ajax_knows',array('type'=>'_sel'))}>?sectionid={value}" autocomplete="off">
				  			<option value="0">全部</option>
				  		</select>
				  		<select class="combox" id="iknowsselect" autocomplete="off">
				  		<option value="0">全部</option>
				  		</select>
						<input type="button" class="btn btn-primary btn-xs" value="选定" onclick="javascript:setKnowsList('questionknowsid','iknowsselect','+');" autocomplete="off">
			  			<input type="button" class="btn btn-primary btn-xs" value="清除" onclick="javascript:setKnowsList('questionknowsid','iknowsselect','-');" autocomplete="off">
                    </div>
                    <div class="col-sm-3" id="for_select_div">
					
                    </div>
                </div>

				 <div class="form-group">
                    <label class="col-sm-2 control-label">知识点</label>
                    <div class="col-sm-7">
					<volist name="data['quest2knows']" id="vo">
	<input type="hidden" name="questionsubjectid[<{$vo.qkquestionsubjectid}>]" class="questionsubjectid" value="<{$vo.qkquestionsubjectid}>">
	<input type="hidden" name="qkknowsid[<{$vo.qkknowsid}>]" class="qkknowsid" value="<{$vo.qkknowsid}>">
	<input type="hidden" name="questionsectionid[<{$vo.questionsectionid}>]" class="questionsectionid" value="<{$vo.questionsectionid}>">
					</volist>
                       <textarea  rows="4"   name="questionknowsid" id="questionknowsid" readonly="" autocomplete="off"><{$data.questionknowsid}></textarea>
                    </div>
                    <div class="col-sm-3">
                    </div>
                </div>
				
 
				
				<div class="form-group">
                    <label class="col-sm-2 control-label">题干</label>
                    <div class="col-sm-7">
                      <textarea rows="4"  name="question" autocomplete="off"><{$data.question}></textarea>
                    </div>
                    <div class="col-sm-3">
                    </div>
                </div>
				
				
				<div class="form-group">
                    <label class="col-sm-2 control-label">难度</label>
                    <div class="col-sm-7">
                      <select name="questionlevel" class="input-medium" autocomplete="off">
								<volist name="questionlevel" id="vo">
						  			<option  <if condition="$key eq $data['questionlevel']">selected="selected"</if> value="<{$key}>"><{$vo}></option>
								</volist>	
					  </select>
                    </div>
                    <div class="col-sm-3">
                    </div>
                </div>
				<div class="form-group">
						<label class="col-sm-2 control-label" >题型</label>
						<div class="col-sm-7">
							 <select onchange="questiontype_box(this)"  id="selectID" name="questiontype" class="input-medium" autocomplete="off">
							 <option value=""> 请选择题型</option>
									<volist name="questiontype_list" id="vo">
										<option questchoice="<{$vo.questchoice}>" questsort="<{$vo.questsort}>"  <if condition="$data['questiontype'] eq $vo['questid']">selected="selected"</if> value="<{$vo.questid}>"><{$vo.questype}></option>
									</volist>			
							</select>
						</div>
						<div class="col-sm-3">
						</div>
					</div>
				<if condition="$type eq 1 || $pid ">
					
					<div class="form-group" id="questionanswer_box">
						<label class="col-sm-2 control-label">备选项</label>
						<div class="col-sm-7">
										<div  class="box" id="questionanswer_box_1">
										<p>
										<input type="text" id="select_value" style="width:570px" placeholder="填写选项" />
										<input type="button" class="btn btn-primary btn-xs" value="添加选项" onclick="add_select()" >
										</p>

										<div id="business-wrapper">
						 
										<volist name="data['questionanswer']" id="vo">
										   <span class="questchoice <if condition="$vo['choose']">active</if>"  onclick="set_choose(this)">
											<{$vo.text}>
											<input type="hidden" name="questionanswer[<{$i}>][text]" value="<{$vo.text}>" />
											<input type="hidden" class="choose_input"  name="questionanswer[<{$i}>][choose]" value="<{$vo.choose}>" />
											</span> 
										</volist>	
										</div>
									 
										</div>
								 
										<!--结束-->
										<small class="help-block" data-bv-validator="notEmpty" data-bv-for="questiondescribe" data-bv-result="INVALID" style=""></small>
								 
						</div>
						<div class="col-sm-3">
						</div>
					</div>	
					<div class="form-group none" id="questionanswer_box_5">
						<label class="col-sm-2 control-label">分录题</label>
						 <div class="col-sm-7" id="questionanswer_box_5_27">
						 <p>
						 <label><input type="radio" checked="checked" onclick="questionanswer_box_5()"  name="questionanswer_5[type]" value="1" />分录题</label>&nbsp;&nbsp;
						<label><input type="radio" <if condition="$data['questionanswer']['type'] eq 2">checked="checked"</if> onclick="questionanswer_box_5()" name="questionanswer_5[type]" value="2"/>金额计算题</label>&nbsp;&nbsp;<label class="none questionanswer_box_div" id="questionanswer_box_5_2"><input type="text" value="<{$data['questionanswer'][2]['money']}>" name="questionanswer_5[2][money]" placeholder="金额" />元</label>
						</p>
									 <div id="questionanswer_box_5_1" class="questionanswer_box_div">
										<p>
										科目：<span class="area"></span>
										<label><input checked="checked" type="radio" name="questionanswer_5_type" value="1" />贷</label>
										<label><input type="radio" name="questionanswer_5_type" value="2"/>借</label>
										<input type="text" value="0"  id="addmoney" style="width:50px; padding-left:5px;" placeholder="金额"/>元
										<input type="button" class="btn btn-primary btn-xs" value="添加选项" onclick="add_select_5(27)" >
										
										</p>

										<div id="business-wrapper-5">
										 <volist name="data['questionanswer']['1']" id="vo">
											 <div class="questchoice">
											 <span class=""  >
											<{:htmlspecialchars_decode($vo['text'])}>
											<input type="hidden" name="questionanswer_5[1][<{$i}>][text]" value="<{$vo.text}>" />
											<input type="hidden" name="questionanswer_5[1][<{$key}>][code]" value="<{$vo.code}>" />
											<input type="hidden" name="questionanswer_5[1][<{$key}>][money]" value="<{$vo.money}>" />
											<input type="hidden" name="questionanswer_5[1][<{$key}>][type]" value="<{$vo.type}>" />
											
											</span> 
											 <a class="btn btn-primary btn-xs" onclick="del_questchoice(this)" >删除</a>
											 </div>
											 </volist>
										</div>
									  </div>
									    
									  
								 
										<!--结束-->
										<small class="help-block" data-bv-validator="notEmpty" data-bv-for="questiondescribe" data-bv-result="INVALID" style=""></small>
								 
						</div>
						<div class="col-sm-3">
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-sm-2 control-label">习题解析</label>
						<div class="col-sm-7">
						   <textarea rows="4"   name="questiondescribe" autocomplete="off"><{$data.questiondescribe}></textarea>
						</div>
						<div class="col-sm-3">
						</div>
					</div>
				</if>
				
				
				<div class="control-group">
				  	<div class="col-sm-offset-2 col-sm-7">
					<input type="submit" onclick="return check()" class="btn btn-primary"  value="提交" />
					 
				</div>
			 
				 
			</form>
        </div>
    </div>
   

        </div>
    </section>
                
                </div>
<style>
#questionanswer_box .questchoice{ width:auto; float:none; margin-left:0px; display:block; text-align:left;white-space:normal; text-align:left}
#questionanswer_box_5 .questchoice{ width:100%;  margin-left:0px; display:block;}
#questionanswer_box_5 .questchoice .btn-default{ width:400px; float:left; text-align:left;white-space:normal; text-align:left }
#questionanswer_box_5 .questchoice a{ float:left; margin-top:5px;}
#questionanswer_box,.box{ display:none}
.none{ display:none}
.form-group textarea{ width:100%;}
.s_left{ float:left}
.s_right{ float:right}
</style>
<!--对与错的选项-->
<div  class="box" id="questionanswer_box_4">
	<span class="questchoice" onclick="set_choose(this)" >
	对
	<input type="hidden" name="questionanswer[1][text]" value="对" />
	<input type="hidden"  class="choose_input"  name="questionanswer[1][choose]" value="0" />
	</span>
	<span class="questchoice"  onclick="set_choose(this)">
	错
	<input type="hidden" name="questionanswer[2][text]" value="错" />
	<input type="hidden"   class="choose_input" name="questionanswer[2][choose]" value="0" />
	</span>									 
</div>
 <!--对与错的选项--> 
<script type="text/javascript">
	var questchoice_leng=$("#business-wrapper .questchoice").length;
	/*******添加选项****/
	function add_select(){
		var select_value=$("#select_value").val();
		$("#select_value").val('');
		var questchoice=$("#selectID").find("option:selected").attr("questchoice");
		if(select_value!=""){
			questchoice_leng++;
			var input='<input type="hidden" name="questionanswer['+questchoice_leng+'][text]" value="'+select_value+'" />';
			input+='<input type="hidden" class="choose_input"  name="questionanswer['+questchoice_leng+'][choose]" value="0" />';
			var html='<span onclick="set_choose(this)"  class="questchoice">'+select_value+input+'</span> ';
		}
		$("#business-wrapper").append(html);
		check();
	}
	
	/********设置成答案****/
	function set_choose(obj){
		var questchoice=$("#selectID").find("option:selected").attr("questchoice");
		var choose=$(obj).find("input").eq('1').val();
		if(choose==0){
			/*****多选题**/
			if(questchoice==2 || questchoice==3){
				
			}
			/*****单选题，判断题**/
			if(questchoice==1 || questchoice==4){
				$(".choose_input").val(0);
				$(".questchoice").removeClass("active");
			}
			$(obj).addClass("active");
			$(obj).find("input").eq('1').val(1);
		}else{
			$(obj).removeClass("active");
			$(obj).find("input").eq('1').val(0);
		}
		check();
	}
	 
	/********选择题型********/
 	 function questiontype_box(){
		var questsort=$("#selectID").find("option:selected").attr("questsort");
		var questchoice=$("#selectID").find("option:selected").attr("questchoice");
		
		/*********客观题****/
		if(questchoice==1 || questchoice==2 || questchoice==3 || questchoice==4 ){
			$("#questionanswer_box").show();
		}else{
			$("#questionanswer_box").hide();
		}
		/****主观题和冒题**/
		if(questsort==1 || questsort==3){
			$("#questionanswer_box").hide();
		}
		
		$(".box").hide();
		$("#questionanswer_box_1").show();
		$("#questionanswer_box_1 p").show();
		$("#business-wrapper").html("");
		/*****判断题****/
		if(questchoice==4){
			$("#questionanswer_box_1 p").hide();
			var html=$("#questionanswer_box_4").html();
			$("#business-wrapper").append(html);
		}
		/*****分录题*****/
		if(questchoice==5){
			$("#questionanswer_box_5").show();	
		}else{
			$("#questionanswer_box_5").hide();	
		}
	 }
	<!--修改时-->
	 <if condition="$data">
	 	$(function(){
			var questsort=$("#selectID").find("option:selected").attr("questsort");
			var questchoice=$("#selectID").find("option:selected").attr("questchoice");
			/*********客观题****/
			if(questchoice==1 || questchoice==2 || questchoice==3 || questchoice==4 ){
				$("#questionanswer_box").show();
				$("#questionanswer_box_1 p").hide();
			}else{
				$("#questionanswer_box").hide();
			}
			/****主观题和冒题**/
			if(questsort==1 || questsort==3){
				$("#questionanswer_box").hide();
			}
				$(".box").hide();
				$("#questionanswer_box_1").show();
				/*****判断题****/
				if(questchoice==4){
					$("#questionanswer_box_1 p").hide();
				}
				/*****分录题*****/
			if(questchoice==5){
				$("#questionanswer_box_5").show();	
			}else{
				$("#questionanswer_box_5").hide();	
			}
		})
	 </if>
	 /********分录题***/
	 $(function(){
		 questionanswer_box_5();
	})
	 function questionanswer_box_5(){
		 var i=$("[name='questionanswer_5[type]']:checked").val();
		 $(".questionanswer_box_div").hide();
		$("#questionanswer_box_5_"+i).show();	 
	}
	function del_questchoice(obj){
		$(obj).parent().remove();	
	}
	var lng=$("#questionanswer_box_5 .questchoice").length;
	function add_select_5(i){
		var type=$("#questionanswer_box_5_"+i).find("[name='questionanswer_5_type']:checked").val();
		var addmoney=$("#questionanswer_box_5_"+i).find("#addmoney").val();
		var cate_id=$("#questionanswer_box_5_"+i).find(".area select option:selected");
		var type_str=""
		if(type==1){
			type_str="贷";
		}else{
			type_str="借";
		}
		var cate_name=new Array();
		$.each(cate_id,function(i,v){
			if($(v).val() > 0){
				cate_name.push($(v).text());
			}
		}) 
		cate_name=cate_name.join("-");
		if(cate_name==""){
			alert("请选择科目");
			return false;
		}
		if(!(addmoney>0)){
			alert("金额要大于0");
			return false;	
		}
		lng++;
		var code=$(cate_id).attr("code");
		var text="<span class='s_left'>"+type_str+"&nbsp;&nbsp;:"+cate_name+"</span><span class='s_right'>"+addmoney+"元</span>";
		var html=""
		html='<div class="questchoice">';
		html+=' <div class="btn btn-default" >';
		html+=text;
		html+='<input type="hidden" name="questionanswer_5[1]['+lng+'][type]" value="'+type+'" />';
		html+='<input type="hidden" name="questionanswer_5[1]['+lng+'][text]" value="'+text+'" />';
		html+='<input type="hidden" name="questionanswer_5[1]['+lng+'][money]" value="'+addmoney+'" />';
		html+='<input type="hidden" name="questionanswer_5[1]['+lng+'][code]" value="'+code+'" />';
		html+='</div>'; 
		html+='<a class="btn" onclick="del_questchoice(this)" >删除</a>';
		html+='</div>';
		$("#questionanswer_box_5_"+i).find("#business-wrapper-5").append(html);
	//	alert(addmoney);
		//alert(type_str);
	}
</script>    

<!--表单验证-->
<script type="text/javascript">

function check(){
	var questchoice=$("#selectID").find("option:selected").attr("questchoice");
	var questchoice_leng=$("#business-wrapper .questchoice").length;
	var active_leng=$("#business-wrapper .active").length;
	var has_error=0;
	if(questchoice==2){
		if(questchoice_leng<2){
			has_error=1;
			tip='备选项不能少于两项，请设置备选项';
			$("#questionanswer_box").addClass("has-error");
			$("#questionanswer_box").find(".help-block").html(tip);
			return false;
		}
		if(active_leng==0){
			has_error=2;
			tip='请设置备选项的答案';
			$("#questionanswer_box").addClass("has-error");
			$("#questionanswer_box").find(".help-block").html(tip);
			return false;
		}
	}
	if(has_error==0){
		$("#questionanswer_box").removeClass("has-error").addClass("has-success");
		$("#questionanswer_box").find(".help-block").html("");
	}
	$(".form-horizontal").data('bootstrapValidator').resetForm();
	return true;
 
}


$(function(){
    $(".form-horizontal").bootstrapValidator({
        message: '您填入的值不合法',
        fields:{
            questionknowsid: {
                message: '知识点',
                validators: {
                    notEmpty: {
                        message: '请选择知识点'
                    },
                }
            },
			 question: {
                message: '题干',
                validators: {
                    notEmpty: {
                        message: '题干不能为空'
                    },  
                }
            },
			 questiontype: {
                message: '题型',
                validators: {
                    notEmpty: {
                        message: '请选择题型'
                    },  
                }
            },
			questiondescribe: {
                message: '习题解析',
                validators: {
                    notEmpty: {
                        message: '习题解析不能为空'
                    },  
                }
			 },

        }
    });
	
 
});
</script>
 <script type="text/javascript" src="/Public/Js/select.js"></script>
 <script>
 $(".area").cateList();
 </script>  
 
 